package cn.edu.cdp.dumpling.controller;

import cn.edu.cdp.dumpling.entity.OrderList;
import cn.edu.cdp.dumpling.service.OrderListService;
import cn.edu.cdp.dumpling.util.R;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
//@CrossOrigin
@RequestMapping("/order_lists")
public class OrderListController {

    private final OrderListService orderListService;

    public OrderListController(OrderListService orderListService) {
        this.orderListService = orderListService;
    }

    // 查看
    @GetMapping
    public R list(@RequestParam("consumer_id") Integer consumerId) {
        List<OrderList> list;
        if (consumerId != null) {
            list = orderListService.getOrderListAndDetail(consumerId);
        } else {
            return R.error("用户没有登录");
        }
        if (list == null || list.isEmpty())
            return R.error("查询失败");
        else
            return R.success("查询成功", list);
    }

    // 修改
    @PutMapping
    public R updateById(@RequestBody OrderList orderList) {
        if (orderListService.updateById(orderList))
            return R.success("修改成功", null);
        else
            return R.error("修改失败");
    }
}
